﻿using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using System.Collections;
using System.Linq;
using Infrastructure.Utility.Core.Extensions;
using System.Security.Cryptography;
using System.Text;
using System.Web;
using System.Reflection;

namespace Infrastructure.Utility.Core.CommonUtility
{
    public static class StringUtility
    {
        #region 字符串比较

        public static int StringDateCompare(this string date1, string date2)
        {
            DateTime.TryParse(date1, out DateTime d1);
            DateTime.TryParse(date2, out DateTime d2);
            return DateTime.Compare(d1, d2);
        }

        #endregion


        #region 字符串脱敏

        /// <summary>
        /// 手机号脱敏
        /// </summary>
        /// <param name="mobile"></param>
        /// <returns>返回格式：137****5678</returns>
        public static string DesensitizeMobile(this string mobile)
        {
            return DesensitizeString(mobile, pre: 3, tail: 4);
        }

        /// <summary>
        /// userLoginName脱敏
        /// </summary>
        /// <param name="userLoginName"></param>
        /// <returns>返回格式：yl1********50</returns>
        public static string DesensitizeUserLoginName(this string userLoginName)
        {
            return DesensitizeString(userLoginName, pre: 3, tail: 2);
        }


        /// <summary>
        /// 身份证号脱敏
        /// </summary>
        /// <param name="idCard"></param>
        /// <returns>返回格式：1****************9</returns>
        public static string DesensitizeIdCard(this string idCard)
        {
            return DesensitizeString(idCard, pre: 1, tail: 1);
        }

        /// <summary>
        /// QQ脱敏
        /// </summary>
        /// <param name="qq"></param>
        /// <returns>返回格式：12****89</returns>
        public static string DesensitizeQq(this string qq)
        {
            return DesensitizeString(qq, pre: 2, tail: 2);
        }

        /// <summary>
        /// 微信脱敏
        /// </summary>
        /// <param name="wechat"></param>
        /// <returns>返回格式：12****89</returns>
        public static string DesensitizeWechat(this string wechat)
        {
            return DesensitizeString(wechat, pre: 2, tail: 2);
        }

        /// <summary>
        /// 字符串全脱敏
        /// </summary>
        /// <param name="str"></param>
        /// <returns>返回格式：******</returns>
        public static string DesensitizeStrAll(this string str)
        {
            return DesensitizeString(str, pre: 0, tail: 0);
        }

        /// <summary>
        /// 字符串部分脱敏
        /// </summary>
        /// <param name="str">字符串</param>
        /// <param name="pri">头部字符串长度</param>
        /// <param name="tail">尾部字符串长度</param>
        /// <returns>返回格式：pre位+****+tail位</returns>
        public static string DesensitizeString(this string str, int pre = 0, int tail = 0)
        {
            var ret = string.Empty;
            try
            {
                if (!string.IsNullOrWhiteSpace(str))
                {
                    if (pre < 0 ||
                        tail < 0 ||
                        pre >= str.Length ||
                        tail >= str.Length ||
                        pre + tail >= str.Length)
                    {
                        return "********";
                    }

                    var preStr = pre <= 0 ? string.Empty : str.Substring(0, pre);
                    var tailStr = tail <= 0 ? string.Empty : str.Substring(str.Length - tail);

                    var star = new string('*', str.Length - pre - tail);
                    //var star = string.Concat(Enumerable.Repeat("*", str.Length - pre - tail));

                    ret = $"{preStr}{star}{tailStr}";
                }
            }
            catch
            {
                ret = "******";
            }

            return ret;
        }

        public static string DesensitizationMobile(this string mobile)
        {
            var ret = string.Empty;
            if (!string.IsNullOrWhiteSpace(mobile))
            {
                if (mobile.Length != 11)
                {
                    ret = "-";
                }
                else
                {
                    ret = $"{mobile.Substring(0, 3)}****{mobile.Substring(7)}";
                }
            }

            return ret;
        }

        #endregion

        #region 字符串IsBase64String

        public static bool IsBase64String(this string s)
        {
            s = s.Trim();
            return (s.Length % 4 == 0) && Regex.IsMatch(s, @"^[a-zA-Z0-9\+/]*={0,3}$", RegexOptions.None);
        }

        public static string RemoveChar(this string s)
        {
            if (string.IsNullOrWhiteSpace(s)) return "";

            s = Regex.Replace(s, @"\s", "");
            s = Regex.Replace(s, @"\n", "");
            s = Regex.Replace(s, @"\r", "");
            s = Regex.Replace(s, @"\\", "");
            s = Regex.Replace(s, @"/", "");
            return s;
        }

        #endregion

        #region 字符串 为空判断



        public static bool HasValue(this string str)
        {
            return !string.IsNullOrWhiteSpace(str);
        }

        public static bool HasValue(this List<string> strList)
        {
            return strList != null && strList.Any();
        }


        //返回逗号分隔字符串集合
        public static List<string> ToStringList(this string str)
        {
            if (string.IsNullOrWhiteSpace(str)) return new List<string>();

            if (str.IndexOf(',') < 0) return new List<string>() { str.Trim() };

            return str.Trim().Split(',').ToList();
        }

        public static bool HasValue(this DateTime? time)
        {
            return time != null && time.HasValue;
        }

        public static bool HasValue(this bool? isBool)
        {
            return isBool != null && isBool.HasValue;
        }

        #endregion

        #region ListS2L

        static Regex reg = new Regex("\\d+", RegexOptions.Compiled | RegexOptions.Multiline);

        /// <summary>
        /// list String 转化为 list Long 类型
        /// </summary>
        /// <param name="listString"></param>
        /// <returns></returns>
        public static List<long> ListS2L(this List<string> listString)
        {
            if (listString == null) return new List<long>();

            var listlong = new List<long>();
            listString.ForEach(x =>
            {
                if (reg.IsMatch(x))
                    listlong.Add(Convert.ToInt64(x));
                else
                    throw new Exception("数组中有非法数字");
            });
            return listlong;
        }

        #endregion

        #region 字符串随机生产

        /// <summary>
        /// 从一组连续的数据区间范围内，随机抽取不重复的指定个数的数据
        /// </summary>
        /// <param name="pInMinNumber"></param>
        /// <param name="pInMaxNumber"></param>
        /// <param name="pInNeedsCount"></param>
        /// <param name="pOutArrayIdList"></param>
        /// <param name="pOutMsg"></param>
        /// <returns></returns>
        public static bool GetSiphonNumbers(int pInMinNumber, int pInMaxNumber, int pInNeedsCount,
            ref int[] pOutArrayIdList, ref string pOutMsg)
        {
            int total = pInMaxNumber - pInMinNumber + 1;
            int[] sequence = new int[total];
            int strMinValue = pInMinNumber;
            int strMaxValue = pInMaxNumber;
            int strArrayCount = pOutArrayIdList.Length;
            if (total <= 0)
            {
                pOutMsg = "抽最数据个数不能小于0";
                return false;
            }

            if (strMinValue > strMaxValue)
            {
                pOutMsg = "InMinNumber 不能大于 InMaxNumber";
                return false;
            }

            if (pInNeedsCount > total || pInNeedsCount <= 0)
            {
                pInNeedsCount = total;
            }

            if (strArrayCount < pInNeedsCount)
            {
                pOutMsg = "输出数组长度不足";
                return false;
            }

            //生成筛选数据
            for (int i = 0; i < total; i++)
            {
                sequence[i] = strMinValue;
                strMinValue++;
            }

            Random random = new Random(GetRandomSeed());
            //数组中最后一个数的下标
            int end = total - 1;
            //抽数pCount个数
            for (int i = 0; i < pInNeedsCount; i++)
            {
                //产生抽取随机数的下标
                int num = random.Next(0, end + 1);
                //保存抽取到的数
                pOutArrayIdList[i] = sequence[num];
                sequence[num] = sequence[end];
                end--;
            }

            return true;
        }

        private static int GetRandomSeed()
        {
            byte[] bytes = new byte[4];
            System.Security.Cryptography.RNGCryptoServiceProvider rng =
                new System.Security.Cryptography.RNGCryptoServiceProvider();
            rng.GetBytes(bytes);
            return BitConverter.ToInt32(bytes, 0);
        }

        /// <summary>
        /// 获取一个随机索引
        /// </summary>
        /// <param name="pInMinNumber"></param>
        /// <param name="pInMaxNumber"></param>
        /// <param name="pInNeedsCount"></param>
        /// <param name="getIdx">要获取的索引值</param>
        /// <returns></returns>
        public static int GetRandomIndex(int pInMinNumber, int pInMaxNumber, int pInNeedsCount, int getIdx = 0)
        {
            var message = "";
            var outList = new int[1];
            if (GetSiphonNumbers(pInMinNumber, pInMaxNumber, pInNeedsCount, ref outList, ref message))
            {
                if (getIdx < 0 || getIdx >= outList.Length)
                    getIdx = 0;

                return outList[getIdx];
            }

            return -1;
        }

        #endregion

        #region 是否身份证号

        /// <summary>
        /// 是否身份证号
        /// </summary>
        /// <param name="idcardno"></param>
        /// <returns></returns>
        public static bool IsIdCardNo(this string idcardno)
        {
            if (string.IsNullOrWhiteSpace(idcardno))
            {
                return false;
            }

            return Regex.IsMatch(idcardno, @"^(^\d{15}$|^\d{18}$|^\d{17}(\d|X|x))$", RegexOptions.IgnoreCase);
        }

        /// <summary>
        /// 是否手机号
        /// </summary>
        /// <param name="mobile"></param>
        /// <returns></returns>
        public static bool IsMobile(this string mobile)
        {
            if (string.IsNullOrWhiteSpace(mobile))
            {
                return false;
            }

            return Regex.IsMatch(mobile, @"^\d{11}$", RegexOptions.IgnoreCase);
        }

        #endregion

        #region 日期转字符串

        /// <summary>
        /// 日期转字符串D19（格式：yyyy-MM-dd HH:mm:ss）
        /// </summary>
        /// <param name="datetime"></param>
        /// <returns></returns>
        public static string ToStringD19(this DateTime datetime)
        {
            return datetime.ToString("yyyy-MM-dd HH:mm:ss");
        }

        /// <summary>
        /// 日期转字符串D19（格式：yyyy-MM-dd）；为空时返回空字符串
        /// </summary>
        /// <param name="datetime">DateTime?日期</param>
        /// <returns></returns>
        public static string ToStringD19(this DateTime? datetime)
        {
            if (datetime.HasValue)
            {
                return datetime.Value.ToString("yyyy-MM-dd HH:mm:ss");
            }

            return string.Empty;
        }

        /// <summary>
        /// 日期转字符串D19（格式：yyyy-MM-dd）；为空时返回当前时间
        /// </summary>
        /// <param name="datetime">DateTime?日期</param>
        /// <returns></returns>
        public static string ToStringD19OrNow(this DateTime? datetime)
        {
            if (datetime.HasValue)
            {
                return datetime.Value.ToString("yyyy-MM-dd HH:mm:ss");
            }

            return DateTime.Now.ToStringD19();
        }

        /// <summary>
        /// 日期转字符串D10（格式：yyyy-MM-dd）；为空时返回空字符串
        /// </summary>
        /// <param name="datetime">DateTime?日期</param>
        /// <param name="isnullAsNow">若为空时是否转换为当前日期（true:取当前日期，false:返回空）</param>
        /// <returns></returns>
        public static string ToStringD10(this DateTime? datetime)
        {
            if (datetime.HasValue)
            {
                return datetime.Value.ToString("yyyy-MM-dd");
            }

            return string.Empty;
        }

        /// <summary>
        /// 日期转字符串D10（格式：yyyy-MM-dd）
        /// </summary>
        /// <param name="datetime"></param>
        /// <returns></returns>
        public static string ToStringD10(this DateTime datetime)
        {
            return datetime.ToString("yyyy-MM-dd");
        }

        /// <summary>
        /// 日期转时间（格式：HH:mm:ss）
        /// </summary>
        /// <param name="datetime"></param>
        /// <returns></returns>
        public static string ToStringTime8(this DateTime datetime)
        {
            return datetime.ToString("HH:mm:ss");
        }

        /// <summary>
        /// 字符串转日期
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public static DateTime ToDateTime(this string str)
        {
            if (DateTime.TryParse(str, out var time))
            {
                return time;
            }

            return DateTime.MinValue;
        }

        /// <summary>
        /// 字符串转日期
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public static DateTime ToDateTimeOrNow(this string str)
        {
            if (DateTime.TryParse(str, out var time))
            {
                return time;
            }

            return DateTime.Now;
        }

        /// <summary>
        /// 获取当前日期D10（格式：yyyy-MM-dd）
        /// </summary>
        /// <returns></returns>
        public static string DateNowD10Str() => DateTime.Now.ToString("yyyy-MM-dd");


        /// <summary>
        /// 获取当前时间D19（格式：yyyy-MM-dd HH:mm:ss）
        /// </summary>
        /// <returns></returns>
        public static string DateNowD19Str() => DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");

        /// <summary>
        /// 获取明天日期D10（格式：yyyy-MM-dd）
        /// </summary>
        /// <returns></returns>
        public static string DateNextD10Str() => DateTime.Now.AddDays(1).ToString("yyyy-MM-dd");

        #endregion

        #region 查询截至日期处理

        #region 获取日期后一天的起始

        public static DateTime ToNextDayStart(this DateTime dateEnd)
        {
            DateTime nextDay = dateEnd.AddDays(1);
            return new DateTime(nextDay.Year, nextDay.Month, nextDay.Day, 0, 0, 0);
        }

        public static DateTime? ToNextDayStart(this DateTime? dateEnd)
        {
            if (!dateEnd.HasValue())
            {
                return null;
            }

            return ToNextDayStart(dateEnd.Value);
        }
        #endregion

        #region 获取日期的起始（格式：yyyy-MM-dd 00:00:00）
        /// <summary>
        /// 获取日期的起始 格式：yyyy-MM-dd 00:00:00
        /// </summary>
        /// <param name="date"></param>
        /// <returns></returns>
        public static DateTime ToDayBegin(this DateTime date)
        {
            return new DateTime(date.Year, date.Month, date.Day, 0, 0, 0);
        }

        /// <summary>
        /// 获取日期的起始 格式：yyyy-MM-dd 00:00:00
        /// </summary>
        /// <param name="date"></param>
        /// <returns></returns>
        public static DateTime? ToDayBegin(this DateTime? date)
        {
            if (!date.HasValue()) return null;

            return new DateTime(date.Value.Year, date.Value.Month, date.Value.Day, 0, 0, 0);
        }

        /// <summary>
        /// 获取日期的起始 格式：yyyy-MM-dd 00:00:00
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public static DateTime ToDayBegin(this string str)
        {
            return str.ToDateTime().ToDayBegin();
        }
        #endregion

        #region 获取日期的结束 格式：yyyy-MM-dd 23:59:59
        /// <summary>
        /// 获取日期的结束 格式：yyyy-MM-dd 23:59:59
        /// </summary>
        /// <param name="date"></param>
        /// <returns></returns>
        public static DateTime ToDayEnd(this DateTime date)
        {
            return new DateTime(date.Year, date.Month, date.Day, 23, 59, 59);
        }

        /// <summary>
        /// 获取日期的结束 格式：yyyy-MM-dd 23:59:59
        /// </summary>
        /// <param name="date"></param>
        /// <returns></returns>
        public static DateTime? ToDayEnd(this DateTime? date)
        {
            if (!date.HasValue()) return null;

            return new DateTime(date.Value.Year, date.Value.Month, date.Value.Day, 23, 59, 59);
        }

        /// <summary>
        /// 获取日期的结束 格式：yyyy-MM-dd 23:59:59
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public static DateTime ToDayEnd(this string str)
        {
            return str.ToDateTime().ToDayEnd();
        }
        #endregion

        public static TimeSpan GetDayEndTimeSpan(this DateTime date) =>
            DateTime.Now.Date.AddDays(1).AddSeconds(-1).Subtract(DateTime.Now);

        #endregion

        #region 身份证号计算

        /// <summary>
        /// 根据身份证获取性别Code
        /// </summary>
        /// <param name="idCard"></param>
        /// <returns>返回性别Code：F-女，M-男</returns>
        public static string GetGenderCodeFromIdCard(this string idCard)
        {
            string gender = string.Empty;
            try
            {
                if (string.IsNullOrEmpty(idCard))
                {
                    return string.Empty;
                }
                if (!IsIdCardNo(idCard))
                {
                    return string.Empty;
                }

                string tmp = "";
                if (idCard.Length == 15)
                {
                    tmp = idCard.Substring(idCard.Length - 3);
                }
                else if (idCard.Length == 18)
                {
                    tmp = idCard.Substring(idCard.Length - 4);
                    tmp = tmp.Substring(0, 3);
                }
                int sx = int.Parse(tmp);
                int outNum;
                Math.DivRem(sx, 2, out outNum);
                if (outNum == 0)
                {
                    gender = "F";
                }
                else
                {
                    gender = "M";
                }
            }
            catch (Exception)
            {
                gender = string.Empty;
            }

            return gender;
        }


        /// <summary>
        /// 根据身份证获取性别中文名称
        /// </summary>
        /// <param name="IdCard"></param>
        /// <returns>返回性别中文：女，男</returns>
        public static string GetGenderNameFromIdCard(this string IdCard)
        {
            var gender = IdCard.GetGenderCodeFromIdCard();
            return gender.GenderCodeToName();
        }

        /// <summary>
        /// 根据身份证号获取生日
        /// </summary>
        /// <param name="idCard"></param>
        /// <returns></returns>
        public static string GetBrithdayFromIdCard(this string idCard)
        {
            if (string.IsNullOrEmpty(idCard))
            {
                return string.Empty;
            }

            if (!IsIdCardNo(idCard))
            {
                return string.Empty;
            }

            string birthday = "1900-01-01";
            if (idCard.Length == 15)
            {
                birthday = idCard.Substring(6, 6).Insert(4, "-").Insert(2, "-");
            }
            else if (idCard.Length == 18)
            {
                birthday = idCard.Substring(6, 8).Insert(6, "-").Insert(4, "-");
            }

            return birthday;
        }


        /// <summary>
        /// 根据身份证号获取年龄
        /// </summary>
        /// <param name="idCard"></param>
        /// <returns></returns>
        public static int GetAgeFromIdCard(this string idCard)
        {
            if (string.IsNullOrEmpty(idCard))
            {
                return 0;
            }

            if (!IsIdCardNo(idCard))
            {
                return 0;
            }

            string birthDay = GetBrithdayFromIdCard(idCard);

            if (!birthDay.IsDateTime())
            {
                return 0;
            }

            DateTime.TryParse(birthDay, out DateTime birth);

            return DateTime.Now.Year - birth.Year;
        }

        #endregion

        #region Code转Name相关静态函数
        /// <summary>
        /// 服务阶段:Code转换Name
        /// </summary>
        /// <param name="code">code：XQ，ZJ</param>
        /// <returns>返回性别：XQ:学前、ZJ:在籍(枚举)</returns>
        public static string StageCodeToName(this string code)
        {
            if (string.IsNullOrWhiteSpace(code))
            {
                return string.Empty;
            }

            switch (code.ToUpper())
            {
                case "XQ": return "学前";
                case "ZJ": return "在籍";
                default: return string.Empty;
            }
        }

        /// <summary>
        /// 性别:Code转换Name
        /// </summary>
        /// <param name="code">code：F，M</param>
        /// <returns>返回性别：女，男</returns>
        public static string GenderCodeToName(this string code)
        {
            if (string.IsNullOrWhiteSpace(code))
            {
                return string.Empty;
            }

            switch (code.ToUpper())
            {
                case "F": return "女";
                case "M": return "男";
                default: return string.Empty;
            }
        }

        /// <summary>
        /// 考生类别:Code转Name（TKS：统考生、 MSS：免试生）
        /// </summary>
        /// <param name="code">code：TKS，MSS</param>
        /// <returns>返回性别：TKS：统考生、 MSS：免试生</returns>
        public static string StuTypeCodeToName(this string code)
        {
            if (string.IsNullOrWhiteSpace(code))
            {
                return string.Empty;
            }

            switch (code.ToUpper())
            {
                case "TKS": return "统考生";
                case "MSS": return "免试生";
                default: return string.Empty;
            }
        }

        /// <summary>
        /// 婚姻状态:Code转Name
        /// </summary>
        /// <param name="code">code：WH、YH、LH、SO、WZ</param>
        /// <returns>返回性别：WH:未婚、YH:已婚、LH:离婚、SO:丧偶、WZ:未知</returns>
        public static string MarriageStatusCodeToName(this string code)
        {
            if (string.IsNullOrWhiteSpace(code))
            {
                return string.Empty;
            }

            switch (code.ToUpper())
            {
                case "WH": return "未婚";
                case "YH": return "已婚";
                case "LH": return "离婚";
                case "SO": return "丧偶";
                case "WZ": return "未知";
                default: return string.Empty;
            }
        }
        #endregion


        /// <summary>
        /// 解密网关的字符串
        /// </summary>
        /// <param name="decryptString"></param>
        /// <returns></returns>
        public static string GateWayDecryptMobile(this string decryptString)
        {

            if (string.IsNullOrWhiteSpace(decryptString)) return "";
            try
            {
                //特殊字符处理
                decryptString = decryptString.Replace("+", "%2B").Replace("*", "%2A");
                decryptString = HttpUtility.UrlDecode(decryptString);

                var key = "yl2019#$00000000";
                using (var rijndaelCipher = Aes.Create("AesManaged"))
                {
                    rijndaelCipher.Mode = CipherMode.ECB;
                    rijndaelCipher.Padding = PaddingMode.PKCS7;
                    rijndaelCipher.KeySize = 128;
                    rijndaelCipher.BlockSize = 128;
                    byte[] pwdBytes = Encoding.UTF8.GetBytes(key);
                    byte[] keyBytes = new byte[16];
                    int len = pwdBytes.Length;
                    if (len > keyBytes.Length)
                        len = keyBytes.Length;
                    Array.Copy(pwdBytes, keyBytes, len);
                    rijndaelCipher.Key = keyBytes;
                    rijndaelCipher.IV = keyBytes;

                    using var decryptor = rijndaelCipher.CreateDecryptor();
                    byte[] toEncryptArray = Convert.FromBase64String(decryptString);
                    byte[] resultArray = decryptor.TransformFinalBlock(toEncryptArray, 0, toEncryptArray.Length);
                    return UTF8Encoding.UTF8.GetString(resultArray);
                }
            }
            catch (Exception ex)
            {
                string str = ex.Message;
            }

            return decryptString;
        }
        /// <summary>
        /// 对字符串中的多个手机号和身份证号进行脱敏，排除CUST/USER/SCHOOL开头的数字
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public static string DesensitizeMobileAndIdCard(this string input)
        {
            try
            {
                if (string.IsNullOrWhiteSpace(input))
                {
                    return string.Empty;
                }

                #region 1、使用正则表达式匹配手机号，替换中间6位（前三后二中间六个星）
                Regex regex = new Regex(@"\b\d{11}\b");
                MatchCollection matches = regex.Matches(input);
                // 遍历匹配结果，替换手机号中间4位为*号
                foreach (Match match in matches)
                {
                    string keyword = match.Value;
                    string keywordReplace = keyword.Substring(0, 3) + "******" + keyword.Substring(9);
                    input = input.Replace(keyword, keywordReplace);
                }
                #endregion

                #region 2、使用正则表达式匹配身份证号，替换中间13位（前三后二中间六个星）
                // // 2.1、使用正则表达式匹配18位数字
                // var patternMatch = @"\d{17}(\d{1}|x|X)"; //18位数字
                // var regexMatch = new Regex(@$"{patternMatch}");
                // var collectionMatch = regexMatch.Matches(input);
                // var listMatch = collectionMatch.Select(e => e.Value).ToList();
                //
                // // 2.2、使用正则表达式匹配CUST/USER/SCHOOL开头的18位数字
                // var prefixCode = new List<string> { "CLUE", "CUST", "CP", "CL", "USER", "SCHOOL" };
                // var patternWithprefixCode = prefixCode.Select(e => @$"({e}{patternMatch})").ToList();//包含18位数字，且CLUE/CUST/USER/SCHOOL等开头
                // //var patternExcept = @"((CUST)\d{17}(\d{1}|x|X))|((USER)\d{17}(\d{1}|x|X))|((SCHOOL)\d{17}(\d{1}|x|X))"; //包含18位数字，且CLUE/CUST/USER/SCHOOL等开头
                // var patternExcept = string.Join("|", patternWithprefixCode);//包含18位数字，且CLUE/CUST/USER/SCHOOL等开头
                // var regexExcept = new Regex(@$"{patternExcept}");
                // var collectionExcept = regexExcept.Matches(input);
                // var listExceptStr = collectionExcept.Select(e => e.Value).ToList();
                // var listExcept = new List<string>();
                // foreach (var item in listExceptStr)
                // {
                //     var key = item;
                //     foreach (var code in prefixCode)
                //     {
                //         key = key.Replace(code, "");
                //     }
                //     listExcept.Add(key);
                // }
                //
                // // 2.3、排除多余的匹配项
                // var list = listMatch.Except(listExcept).ToList();
                //
                // // 2.4、遍历匹配结果，替换配替换身份证号中间8位为*号
                // foreach (string keyword in list)
                // {
                //     string keywordReplace = keyword.Substring(0, 3) + "******" + keyword.Substring(16);
                //     input = input.Replace(keyword, keywordReplace);
                // }
                #endregion


                return input;
            }
            catch
            {
                return input;
            }
        }

 
    }
}